package com.crm.system.controller.orderManager;

import com.crm.common.model.DataResponse;
import com.crm.common.model.DhPageInfo;
import com.crm.common.model.DhResponse;
import com.crm.common.model.Enum.ResponseCodeEnum;
import com.crm.model.qo.orderManager.OrderRawDataQO;
import com.crm.model.vo.orderManager.OrderRawDataVO;
import com.crm.system.service.orderManager.OrderRawDataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @ Author ：pym
 * @ Date   ：2021/7/23 9:59
 */
@RestController
@RequestMapping("/orderRawData")
@Slf4j
public class OrderRawDataController {
    @Autowired
    private OrderRawDataService orderRawDataService;

    /**
     * 订单原始数据
     * @Author pym
     * @Date  2021/7/23 11:07
     * @param request
     * @param pageIndex -页码
     * @param pageSize -分页大小
     * @param sortName -排序列名字
     * @param sortOrder -排序规则(asc/desc)
     * @param orderRawDataQO -查询条件
     * @return {@link {com.crm.common.model.DataResponse}}
     */
    @PostMapping("/orderRawDataList")
    public DataResponse orderRawDataList(HttpServletRequest request,
                                         @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                         @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                         @RequestParam(value="sortName",required = false) String sortName,//排序列名字
                                         @RequestParam(value="sortOrder",required = false) String sortOrder,//排序规则(asc/desc)
                                         OrderRawDataQO orderRawDataQO//查询条件
    ){
        try{
            DhPageInfo<OrderRawDataVO> orderRawDataList = orderRawDataService.selectOrderRawDataList(pageIndex, pageSize, sortName, sortOrder, orderRawDataQO);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),orderRawDataList);
        }catch(Exception e){
            log.error("orderRawData orderRawDataList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 发兑换码
     * @Author baijian
     * @Date  2021/7/20 11:00
     * @return {@link {com.crm.common.model.DataResponse}}
     */
    @PostMapping("/sendExchangeCode")
    public DataResponse sendExchangeCode(){
        try{
            Integer num = orderRawDataService.sendExchangeCode();
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),num);
        }catch(Exception e){
            log.error("customerRawData sendExchangeCode error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

}
